﻿using System;

namespace Quail
{
    /// <summary>
    /// Delegate for on complete events
    /// </summary>
    /// <param name="page">a reference to this page</param>
    public delegate void OnWebPageCompleteEvent(IWebPage page);

    /// <summary>
    /// Delegate for failed events
    /// </summary>
    /// <param name="page">This web page</param>
    /// <param name="error">The exception</param>
    public delegate void OnFailedEvent(IWebPage page, Exception error);

    /// <summary>
    /// Interface for WebPage
    /// </summary>
    public interface IWebPage
    {
        /// <summary>
        /// Gets the current web page location
        /// </summary>
        string Location { get; }

        /// <summary>
        /// Gets the current web page location (without throwing an exception)
        /// </summary>
        string SafeLocation { get; }

        /// <summary>
        /// Waits for the web page to finish loading and makes sure this web page exists
        /// </summary>
        /// <param name="ysod">The type of YSOD check</param>
        void Sync(YSODCheckTypes ysod = YSODCheckTypes.CheckForYSOD);

        /// <summary>
        /// Waits for any web page to finish loading
        /// </summary>
        /// <param name="ysod">The type of YSOD check</param>
        void SyncAnyPage(YSODCheckTypes ysod = YSODCheckTypes.CheckForYSOD);

        /// <summary>
        /// Gets the current ActiveTask
        /// </summary>
        Task ActiveTask { get; }

        /// <summary>
        /// Gets a value indicating whether the page exists
        /// </summary>
        bool Exists { get; }

        /// <summary>
        /// Gets the Html for the page
        /// </summary>
        string Html { get;  }

        /// <summary>
        /// Called when the Sync() method completes successfully
        /// </summary>
		event OnWebPageCompleteEvent OnSyncIsCompleteEvent;

        /// <summary>
        /// Called when the Sync() method fails
        /// </summary>
        event OnFailedEvent OnSyncFailedEvent;
    }
}
